package com.iwomy.secureplat.platform.service.impl;

import cn.hutool.core.util.ArrayUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iwomy.secureplat.platform.dto.BasicDeviceEventRecordDTO;
import com.iwomy.secureplat.platform.entity.BasicDeviceEventRecordEntity;
import com.iwomy.secureplat.platform.mapper.BasicDeviceEventRecordMapper;
import com.iwomy.secureplat.platform.service.BasicDeviceEventRecordService;
import org.springframework.stereotype.Service;
/**
 * 设备事件记录表
 *
 * @author pig
 * @date 2023-11-21 15:10:39
 */
@Service
public class BasicDeviceEventRecordServiceImpl extends ServiceImpl<BasicDeviceEventRecordMapper, BasicDeviceEventRecordEntity> implements BasicDeviceEventRecordService {
	@Override
	public Page getBasicDeviceEventRecordPage(Page page, BasicDeviceEventRecordDTO basicDeviceEventRecordDTO) {
		LambdaQueryWrapper<BasicDeviceEventRecordEntity> wrapper = Wrappers.lambdaQuery();

		if (ObjectUtil.isNotEmpty(basicDeviceEventRecordDTO.getEventTypeId())) {
			wrapper.eq(BasicDeviceEventRecordEntity::getEventTypeId, basicDeviceEventRecordDTO.getEventTypeId());
		}

		if (ArrayUtil.isNotEmpty(basicDeviceEventRecordDTO.getCreateTime())) {
			wrapper.ge(BasicDeviceEventRecordEntity::getCreateTime, basicDeviceEventRecordDTO.getCreateTime()[0]).le(BasicDeviceEventRecordEntity::getCreateTime,
					basicDeviceEventRecordDTO.getCreateTime()[1]);
		}

		return baseMapper.selectPage(page, wrapper);
	}
}